package com.yang.biz.modular.taskcenter.result;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yang.biz.modular.taskcenter.entity.Task;
import lombok.Data;

/**
 * @author: yangjianzhi
 * @version1.0
 */
@Data
public class TaskResult {
    private String id;
    private String userId;
    private String category;
    private String operator;
    private String description;
    private String progress;
    private String status;
    private String isRead;
    private String createTime;
    private String updateTime;

    /**
     * 做了处理
     */
    private JSONObject ext;

    public static Task voToObj(TaskResult taskResult) {
        Task task = new Task();
        BeanUtil.copyProperties(taskResult, task);
        JSONObject extJson = taskResult.getExt();
        if(extJson != null) {
            task.setExtJson(extJson.toString());
        }
        return task;
    }

    public static TaskResult objToVo(Task task) {
        TaskResult taskResult = new TaskResult();
        BeanUtil.copyProperties(task, taskResult);
        String extJson = task.getExtJson();
        if(StrUtil.isNotBlank(extJson)) {
            taskResult.setExt(JSONUtil.parseObj(extJson));
        }else {
            taskResult.setExt(JSONUtil.createObj());
        }
        return taskResult;
    }
}
